#!/bin/bash
#替换源
sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
#　安装依赖
apt-get update && apt-get install -y curl wget git make build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev openssl libsqlite3-dev libxml2 libxml2-dev libxslt1-dev liblzma-dev xz-utils tk-dev
# 安装pyenv
curl -L -o pyenv-installer.sh https://gitee.com/batcom/scripts/raw/master/pyenv-installer.sh && bash pyenv-installer.sh
echo 'export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
'>>~/.bashrc 
source ~/.bashrc
source ~/.bashrc
mkdir ~/.pyenv/cache
curl -L -o ~/.pyenv/cache/Python-3.7.8.tgz http://tools.gloryonly.com/Python-3.7.8.tgz
curl -L -o ~/.pyenv/cache/Python-3.8.5.tgz http://tools.gloryonly.com/Python-3.8.5.tgz
curl -L -o ~/.pyenv/cache/Python-3.7.8.tar.xz http://tools.gloryonly.com/Python-3.7.8.tar.xz
curl -L -o ~/.pyenv/cache/Python-3.8.5.tar.xz http://tools.gloryonly.com/Python-3.8.5.tar.xz
# 安装不同版本python
pyenv install 3.7.8
pyenv install 3.8.5
pyenv global 3.7.8

# 配置python 源
mkdir ~/.pip
echo '[global]
timeout = 60
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com'>>~/.pip/pip.conf
python -m pip install --upgrade pip
# 安装配置virtualenvwrapper
pip install virtualenv virtualenvwrapper
mkdir ~/.virtualenvs
pyenvbin=$HOME/.pyenv/versions/3.7.8/bin
if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
   echo 'export WORKON_HOME=$HOME/.virtualenvs
   export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
   source /usr/local/bin/virtualenvwrapper.sh'>>~/.bashrc
fi
if [ -f $pyenvbin/virtualenvwrapper.sh ]; then
   echo 'export WORKON_HOME=$HOME/.virtualenvs
   export VIRTUALENVWRAPPER_VIRTUALENV='$pyenvbin'/virtualenv
   source '$pyenvbin'/virtualenvwrapper.sh'>>~/.bashrc
fi
source ~/.bashrc